package com.example.kotlin

fun main(args: Array<String>) {

    val result = listOf(1, 2, 3).flatMap {
        if (it > 1) {
            return@flatMap listOf(it, it * 2)
        } else {
            return@flatMap listOf(it)
        }
    }
    println(result)
    println("---------------------------------------分割线-------------------------------------")


    // 调用示例
    val result1 = checkNumber(10) // "Positive"
    println(result1)
    println("---------------------------------------分割线-------------------------------------")


    // 调用示例
    val maximum = max(5, 10) // 10
    println(maximum)
    println("---------------------------------------分割线-------------------------------------")

    val numbers = listOf(1, -2, 3, 0, -5)
    val results = numbers.map { number ->
        if (number > 0) {
            "Positive: $number"
        } else if (number < 0) {
            "Negative: $number"
        } else {
            "Zero"
        }
    } // 结果: ["Positive: 1", "Negative: -2", "Positive: 3", "Zero", "Negative: -5"]
    println(results)
    println("---------------------------------------分割线-------------------------------------")

    // 调用示例
    val processed =
        processNumbers(listOf(1, 2, 3, 4, 5)) // 结果: ["1 is odd", "2 is even", "3 is odd", "4 is even", "5 is odd"]
    println(processed)
    println("---------------------------------------分割线-------------------------------------")


}

fun checkNumber(num: Int): String {
    return if (num > 0) {
        "Positive"
    } else if (num < 0) {
        "Negative"
    } else {
        "Zero"
    }
}

fun max(a: Int, b: Int): Int {
    return if (a > b) a else b
}

fun processNumbers(numbers: List<Int>): List<String> {
    return numbers.map { number ->
        return@map if (number % 2 == 0) {
            "$number is even"
        } else {
            "$number is odd"
        }
    }
}
